package com.example.es.myapplication;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.zqm.neu612.Adapter.NewsListAdapter;
import com.example.zqm.neu612.JavaBean.Food;
import com.example.zqm.neu612.JavaBean.Shop;
import com.example.zqm.neu612.Model.ShopModel;
import com.example.zqm.neu612.R;
import com.example.zqm.neu612.Service.FoodService;
import com.example.zqm.neu612.Service.ShopService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;


public class HomeFragment extends Fragment {
    public List<Shop> shops;
    private RecyclerView recyclerView;
    private ImageView targetImageView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate( R.layout.fragment_home, container, false);
        recyclerView = (RecyclerView) v.findViewById(R.id.rrr);

        targetImageView = (ImageView) v.findViewById(R.id.news_thumb);

        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));//设置布局

        shouData();
        return v;
    }

    private void shouData() {

//        //联网获取网络上的数据
//        Retrofit retrofit = new Retrofit.Builder()
//                .baseUrl("http://172.24.10.130:8080/")
//                .addConverterFactory(GsonConverterFactory.create())
//                .build();
//        ShopService shopService= retrofit.create(ShopService.class);

        ShopModel shopModel = new ShopModel();

        Call<List<Shop>> call = shopModel.getList();



            call.enqueue(new Callback<List<Shop>>() {
                @Override
                public void onResponse(Call<List<Shop>> call, Response<List<Shop>> response) {
                    shops = response.body();

                    recyclerView.setAdapter(new NewsListAdapter(getActivity(), shops));//设置适配器

                }

                @Override
                public void onFailure(Call<List<Shop>> call, Throwable t) {

                }
            });

    }
}
